<?php
namespace app\common\model;
class User extends Base
{

  protected $autoCheckFields = true;
//用于获取单个会员信息
  public function getUserInfo($where){
      $data = $this->where($where)->limit(1)->find();
      if($data){
        return $data;
      }else{
        return false;
      }
  }
//获得用户列表
  public function getUserByUsername($username){
    $data = $this->where("username =  '$username'")->find();
    return $data;
  }

  public function getUserByUid($uid){
     $where =[
      'uid'=>$uid 
      ];
      $data = $this->where($where)->find();
      return $data;
  }

    public function updateInfo($uid,$info){
      $where['uid'] = $uid;
      $this->where($where)->update($info);
    }
//用户充钱

public function payin($uid,$money,$remark,$bankname="余额")
{
  if($money > 0){
    //用户余额加钱
    $where['uid'] = $uid;
    $this->where($where)->setInc('money',$money);

    //添加财务记录
    $map['uid'] = $uid;
    $user = $this->where($where)->find();
    $dataRecord['uid']       = $uid;
    $dataRecord['username']  = $user['username'];
    $dataRecord['amount']    = $money; //金额
    $dataRecord['remark']    = $remark; //备注
    $dataRecord['bankname']  = $bankname; //银行类型
    $dataRecord['balance']   = $user['money']; //余额
    $dataRecord['create_time']  = time();
    model('financeRecord')->addData($dataRecord); 
  }

}


// 用户余额扣钱
public function payout($uid,$money,$remark,$bankname="余额")
{
  if($money > 0){
    //用户余额加钱
    $where['uid'] = $uid;
    $this->where($where)->setDec('money',$money);

    //添加财务记录
    $map['uid'] = $uid;
    $user = $this->where($where)->find();
    $dataRecord['uid']       = $uid;
    $dataRecord['username']  = $user['username'];
    $dataRecord['amount']    = -$money; //金额
    $dataRecord['remark']    = $remark; //备注
    $dataRecord['bankname']  = $bankname; //银行类型
    $dataRecord['balance']   = $user['money']; //余额
    $dataRecord['create_time']  = time();
    model('financeRecord')->addData($dataRecord); 
  }
}

}
